<%@ page contentType="text/html; charset=utf-8"%>
<div>
<button id="saveBtn">保存</button>
<button id="usersBtn">所有用户</button>
</div>
<input type="hidden" name="bean.id" value="${bean.id}" />
<input type="hidden" name="bean.parent.id" value="${bean.parent.id}" id="parent"/>
<table border="0" cellspacing="1" align="center" class="table">
	<caption class="caption">
		部门详细信息
	</caption>
	<tr>
	<td>上级</td>
	<td><button id="selparent">上级</button>
	<label id="parentName"></label>
	</td>
	</tr>
	<tr>
		<td width="63">
			名称
		</td>
		<td width="257">
			<input name="bean.name" type="text" id="name" value="${bean.name}" />
		</td>
	</tr>
</table>
<script language="javascript">
$(function() {	
	$("#saveBtn").click(function(){
		 saveDepartment() ;
	}).button();
	
	$("#usersBtn").click(function(){
		doAjaxLink("admin/department/users?deptId=${bean.id}");
	}).button();
	$("#selparent").click(function(){
		 if (!userDlg.dialog("isOpen")) {
				userDlg.dialog("open");
		 }	
	}).button();
});
function saveDepartment() {
	var act = "${param.action}!${param.action}";
	var postdata = 'bean.name=' + $("#name").val()+ "&bean.id=${bean.id}";
    if($("#parent").val()!='')
    	postdata+="&bean.parent.id="+$("#parent").val();
	var url=navObj.admin.department.core+act;
	doPost(url,postdata);
	
}
function onSelectNode(event, data) {
	var node = data.rslt.obj;
	var cnt = $("<span></span>");
	var ntype = node.attr("leaf");
	// alert(ntype);
	if (ntype == "user") {
	   alert("不能选择用户,请选择一个部门!");	
	} else {
		$("#parent").val(node.attr("id"));	
		var tins = data.inst;
		$("#parentName").text(tins.get_text(node));
	}
	
}
function userSelectHandler(e, data) {
	// you mabey override this function for your business
	// alert(e);
	onSelectNode(e, data);
}
function userCheck(e,data){
	onSelectNode(e, data);
}
function userUncheck(e,data){
	var a=1-1;
}
function doActionWork() {
	alert(this);
	return false;
	
}
</script>